#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-

import os
# configArray = [
#     "appStrength.lua",
#     "config.lua",
#     "lipLayer.lua",
#     "makeUpBlendMode.lua",
#     "beautyStrength.lua",
#     "makeUpStrength.lua",
# ]

# 获取指定目录下，指定lua文件array中的require路径


def getConfig(path, configArray):
    ''' 获取指定目录下的所有指定后缀的文件名 '''
    f_list = os.listdir(path)
    configContent = ""
    # print f_list
    for i in f_list:
        # os.path.splitext():分离文件名与扩展名
        if os.path.splitext(i)[1] == '.lua':
            if i in configArray:
                configname = i.split(".", 1)[0]

                configContent = configContent+"--local "
                f = open(path+i)
                # data = f.readlines()
                data = f.read().splitlines()
                configContent = configContent+str(configname)+"={\n"
                for i in data:
                    if not len(i):
                        continue
                    if not str(i).find("--"):
                        continue
                    if not str(i).find("function") or not str(i).find("end"):
                        if not str(i).find("function"):
                            configContent = configContent+"local "+i+"\n"
                        else:
                            configContent = configContent+" "+i+"\n"

                    else:
                        configContent = configContent+"local "+i+"\n"

                configContent = configContent+"--}\n\n"

                f.close()
    # print(configContent)
    return(configContent)
